<?php

/**
 * 案例展示分类页面
 * author:wang
 */
define("PHP_IN",true);
require "include/init.php";
require ROOT_PATH."smarty_connection.php";

$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;    //当前分类id
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;   //当前页码

$pagesize = 6;  //每页显示的记录数
$pagestart = ($page - 1) * $pagesize;    //开始显示的位置

$sql = "SELECT * FROM case_type";  //网站分类
$result = $db->query($sql);
$case_type = $db->fetch_all($result);

$where = "isdisplay = 1";
if($cid>0){
    $where .= " AND cid=$cid";
}
$count = 0;
$sql = "SELECT count(*) AS num FROM cases WHERE $where";   //数据库的记录数
$result = $db->query($sql);
$row = $db->fetch_one($result);
$count = $row['num'];

$pagecount = ceil($count/$pagesize);          //所有页数
$page_links = page_links($pagecount,$page,"cases.php?cid=$cid");   //分页处理

$sql = "SELECT * FROM cases WHERE $where ORDER BY caseid DESC LIMIT $pagestart,$pagesize";   //案例展示
$result = $db->query($sql);
$cases = $db->fetch_all($result);

$smarty->assign("case_type",$case_type);
$smarty->assign("cases",$cases);

$smarty->assign("page_links",$page_links);
$smarty->assign("cid",$cid);
$smarty->assign("page",$page);

$smarty->display("cases.tpl");
$db->close();
?>
